package sketchpad.business.dataflow.serializeservice.impl;

import sketchpad.business.dataflow.serializeobj.SerializeObj;
import sketchpad.business.dataflow.serializeservice.SerializeService;

import java.io.*;

public final class SerializeServiceImpl implements SerializeService {
    @Override
    public void serialize(SerializeObj serializeObj, File file){
        try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) {
            oos.writeObject(serializeObj);
        } catch (Exception ignore) { }
    }

    @Override
    public SerializeObj deserialize(File file){
        SerializeObj serializeObj = new SerializeObj.Builder().build();
        try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))){
            serializeObj = (SerializeObj)ois.readObject();
        }catch (Exception ignore){}
        return serializeObj;
    }
}
